package ua.kpi_java_training5.kereia.module2;
import java.util.Random;
/**
 * Created with IntelliJ IDEA.
 * User: Alex
 * Date: 30.05.13
 * Time: 0:21
 * To change this template use File | Settings | File Templates.
 */
public class Fish {
    private boolean live = true;
    private int width;
    private int length;
    private int aquariumWidth, aquariumLength;
    Random rand;
    public Fish(int width, int length, int aquariumWidth, int aquariumLength) {
        this.width = width;
        this.length = length;
        this.aquariumWidth = aquariumWidth;
        this.aquariumLength = aquariumLength;
        rand = new Random();
    }
    /**
     * Set for fish status death false
     */
    public void death() {
        live = false;
    }

    /**
     * Get live status every fish
     * @return
     */
    public boolean getLiveStatus() {
        return live;
    }
    /**
     *
     * @param otherWidth
     */
    public void setWidth(int otherWidth) {
        width = otherWidth;
    }
    /**
     *
     * @return
     */
    public int getWidth() {
        return width;
    }
    /**
     *
     */
    public void setLength(int otherLength) {
        length = otherLength;
    }
    /**
     *
     */
    public int getLength() {
        return length;
    }
    private static int way = 0;
    /**
     * Move Up
     */
    public int goUp(int steps) {
	way = getWidth()+steps;
        return way;
    }
    /**
     * Move Down
     */
    public int goDown(int steps) {
        way = getWidth()-steps;
        return way;
    }

    /**
     * Move Right
     */
    public int goRight(int steps) {
        way = getLength()+steps;
        return way;
    }

    /**
     * Move Left
     */
    public int goLeft(int steps) {
        way = getLength()-steps;
        return way;
    }

    public void go() {

    }

    /**
     * Check width coordinates, beyond or not
     * @param direction
     * @return
     */
    public boolean checkDirectionWidth(int direction) {
        if(direction <= 0 || direction > aquariumWidth) {
            return true;
        }
        setWidth(direction);
        return false;
    }
    /**
     * Check length coordinates, beyond or not
     * @param direction
     * @return
     */
    public boolean checkDirectionLength(int direction) {
        if(direction <= 0 || direction > aquariumLength) {
            return true;
        }
        setLength(direction);
        return false;
    }

    /**
     * Manage direction every fish
     * @param commandName
     * @param steps
     * @return
     */
    public boolean stepControl(String commandName, int steps) {
        if(commandName == "UP") {
            return checkDirectionWidth(goUp(steps));
        } else if(commandName == "DOWN") {
            return checkDirectionWidth(goDown(steps));
        } else if(commandName == "RIGHT") {
            return checkDirectionLength(goRight(steps));
        } else if(commandName == "LEFT") {
            return checkDirectionLength(goLeft(steps));
        } else return false;
    }
}
